var app = new Vue({
    el: "#main-content",
    data:{
        oldManList: {},
        oldMan: {},
        oldManId: "",
        dailyLifeList:{},
        time:''
    },
    mounted: function () {
        this.getOldManList();
    },
    methods: {
        getOldManList: function () {
            axios({
                method: 'get',
                url: "nurse/oldmanlist",
                headers: {'token': localStorage.token,"url":window.location.pathname},
            }).then((ins) => {
                console.log(ins);
                let nhDto = ins.data;
                let oldManList = nhDto.data;
                console.log(oldManList);
                if (nhDto.code == 200) {
                    app.oldManList = oldManList;
                    app.oldMan = oldManList[0];
                    app.oldManId = oldManList[0].id;
                    dailyLifeList(oldManList[0].id);
                } else if (nhDto.code == 500) {
                    location.href = "/500.html";
                }
            })
        },
        setOldManId: function (oldManId) {
            app.oldManId = oldManId;
            app.time = "";
            dailyLifeList(oldManId,app.time);
            getOldManData(oldManId);
        },
        getDailyLifeByDate:function () {
            dailyLifeList (app.oldManId,app.time);
        }
    }
});

//日常生活列表
function dailyLifeList (oldManId,time){
    let data=new URLSearchParams();
    data.append("oldManId",oldManId);
    data.append("time",time);
    axios({
        method: 'post',
        url: "nurse/dailylife",
        data:data,
        headers: {'token': localStorage.token,"url":window.location.pathname},
    }).then((ins) => {
        let nhDto = ins.data;
        let dailyLifeList = nhDto.data;
        if (nhDto.code == 200) {
            console.log(dailyLifeList);
            app.dailyLifeList = dailyLifeList;
        } else if (nhDto.code == 500) {
            location.href = "/500.html";
        }
    })
};
//老人基本信息
function getOldManData(oldManId) {
    let data=new URLSearchParams();
    data.append("oldManId",oldManId);
    axios({
        method: 'post',
        url: "nurse/oldmandata",
        data:data,
        headers: {'token': localStorage.token,"url":window.location.pathname},
    }).then((ins) => {
        console.log(ins.data);
        let nhDto = ins.data;
        let oldMan = nhDto.data;
        if (nhDto.code == 200) {
            app.oldMan = oldMan;
        } else if (nhDto.code == 500) {
            location.href = "/500.html";
        }
    })
};

Vue.filter('dateFormat', function(originVal) {
    const dt = new Date(originVal)

    const y = dt.getFullYear()
    const m = (dt.getMonth() + 1 + '').padStart(2, '0')
    const d = (dt.getDate() + '').padStart(2, '0')

    const hh = (dt.getHours() + '').padStart(2, '0')
    const mm = (dt.getMinutes() + '').padStart(2, '0')
    const ss = (dt.getSeconds() + '').padStart(2, '0')

    return  `${hh}:${mm}:${ss}`
        // ${y}-${m}-${d}
})